﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CrankShaftAnalysisSystem.Devices;
using Modbus.Device;

namespace CrankShaftAnalysisSystem
{
    public partial class FormEastenGauge : Form
    {
        DistanceEastenGauge easten;
        List<Label> lables;
        public FormEastenGauge()
        {
            InitializeComponent();
            lables = new List<Label> { lbCh1, lbCh2, lbCh3, lbCh4, lbCh5 };
            easten = DistanceEastenGauge.Instance;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            for(int i=0;i<lables.Count;i++)
            {
                lables[i].Text = easten.Device.ChannelData[i].ToString("F3");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void FormEastenGauge_FormClosing(object sender, FormClosingEventArgs e)
        {
            Hide();
            e.Cancel = true;
        }

        private void btnMarkZero_Click(object sender, EventArgs e)
        {
            Properties.Settings.Default.Pen1InitPos = easten.Device.ChannelData[0];
            Properties.Settings.Default.Pen2InitPos = easten.Device.ChannelData[1];
            Properties.Settings.Default.Save();
            DistanceEastenGauge.Instance.LoadSetting();
        }

        private void FormEastenGauge_Load(object sender, EventArgs e)
        {
            nmCompress.Value = (decimal)easten.PenTargetCompression;
        }

        private void btnSetTargetCompress_Click(object sender, EventArgs e)
        {
            easten.PenTargetCompression = (double)nmCompress.Value;
            Properties.Settings.Default.PenCompress = easten.PenTargetCompression;
            Properties.Settings.Default.Save();
        }
    }
}
